package com.mydemo.spring.state_machine;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;

/**
 * <p></p >
 *
 * @author liming1
 * @version $Id: BizStateEnum, v1.0 2019-09-25 10:08 liming1 Exp $
 */
@AllArgsConstructor
@Getter
public enum  BizStateEnum {

    WAIT_SIGN("200", "待签约"),

    SIGNED("288", "签约完成"),

    LOANING("300", "放款中"),

    LOANED("388", "放款完成"),

    REFUNDING("401", "退款中"), // 对于消费贷，存在退款情况

    REFUNDED("488", "退款完成"), // 对于消费贷，存在退款情况

    BILL_GEN("501", "生成账单"),

    REPAYING("600", "还款中"),

    PART_REPAID("601", "部分还款"),

    REPAID("688", "已还清"),

    OVERDUE("700", "已逾期"),
    ;

    private String status;

    private String desc;

    public static boolean isIn(String status){
       return Arrays.asList(BizStateEnum.values()).parallelStream().anyMatch(item -> status.equals(item.getStatus()));
    }

    public static BizStateEnum getEnumByStatus(String status){
        Optional<BizStateEnum> any = Arrays.asList(BizStateEnum.values()).parallelStream().filter(item -> status.equals(item.getStatus())).findAny();
        if (any.isPresent()){
            return  any.get();
        }
        return null;
    }
}
